package com.shuoyue.ycgk.ui.pay;

import android.content.Context;
import android.content.Intent;

import androidx.annotation.Nullable;

import com.shuoyue.ycgk.entity.Course;
import com.shuoyue.ycgk.entity.ShopItem;
import com.shuoyue.ycgk.entity.address.OrderAddressBean;
import com.shuoyue.ycgk.entity.course_teacher.AppPrice;
import com.shuoyue.ycgk.ui.mine.coupon.CouponSelectActivity;

/**
 * 预览课程订单
 */
public class PreCourseOrderActivity extends BasePreOrderActivity {
    Course data;
    String appPrice;
    int priceId;
    int subjectTypeId;

    public static void start(Context source, Course data, String price,int priceId,int subjectTypeId) {
        source.startActivity(new Intent(source, PreCourseOrderActivity.class)
                .putExtra("data", data)
                .putExtra("price", price)
                .putExtra("subjectTypeId", subjectTypeId)
                .putExtra("priceId", priceId));
    }

    @Override
    public void initData() {
        super.initData();
        data = (Course) getIntent().getSerializableExtra("data");
        appPrice = getIntent().getStringExtra("price" );
        priceId = getIntent().getIntExtra("priceId", 0);
        subjectTypeId = getIntent().getIntExtra("subjectTypeId", 0);

        setBuyItemAdapter();
        enableAddressSelect();
        mPresenter.getPriceInfo(data.getId(),
                1,
                priceId,
                1,
                addressInfo == null ? null : addressInfo.getId(),
                selectCoupon == null ? null : selectCoupon.getId());
        enAbleCouponSelect();
    }

    @Override
    GoodsItem createGoodsItem() {
        GoodsItem goodsItem = new GoodsItem();
        goodsItem.setCover(data.getCover());
        goodsItem.setId(data.getId());
        goodsItem.setInfo("不支持退换货");
        goodsItem.setPrice(appPrice);
        goodsItem.setTitle(data.getName());
        return goodsItem;
    }

    @Override
    public void setPriceInfo(OrderPriceInfo priceInfo) {
        super.setPriceInfo(priceInfo);
        setPriceToatle(priceInfo.getProductNum(), priceInfo.getTotalPrice(), priceInfo.getPayPrice());
        if (priceInfo.getDeliveryAddress() != null) {
            setAddressInfo(priceInfo.getDeliveryAddress());
        }
    }

    OrderAddressBean addressInfo;





    @Override
    void resetNum(int num) {
        mPresenter.getPriceInfo(data.getId(),
                num,
                priceId,
                1,
                addressInfo == null ? null : addressInfo.getId(),
                selectCoupon == null ? null : selectCoupon.getId());

    }

    @Override
    void initOrderParams(int payType) {
        mPresenter.submitOrder(
                data.getId(),
                orderPriceInfo.getProductNum(),
                priceId,
                1,
                payType,
                addressInfo == null ? null : addressInfo.getId(),
                selectCoupon == null ? null : selectCoupon.getId(),
                message.getText().toString());
    }

    @Override
    void getCoupon() {
        if (orderPriceInfo != null && orderPriceInfo.getHasCoupon() == 1) {
            startActivityForResult(new Intent(mContext, CouponSelectActivity.class)
                            .putExtra("useType", 1)
                            .putExtra("subjectType", subjectTypeId)
                    , 1044);
        }

    }
}
